<?php

    namespace Product\Controller;

    use Common\Controller\AdminbaseController;

    class AdminDataController extends AdminbaseController {

        protected $m_data;

        function _initialize() {
            parent::_initialize();
            $this->m_data= D("Product/Data");
        }



        // 添加商品
        public function add(){
            $id = I("get.id",1);
            if(!empty($id)){
                $item=$this->m_data->where(array('id'=>$id))->find();
                $this->assign("item",$item);
            }

            $this->display();
        }


        // 文章添加提交
        public function add_post(){
            if (IS_POST) {
                $id = I("post.id");

                $insert = array(
                    'content'=>htmlspecialchars_decode(I("post.content")),
                );
                if(empty($id)){
                    $result =$this->m_data->add($insert);
                }else{
                    $result = $this->m_data->where(array("id"=>$id))->save($insert);
                }
                if ($result) {
                    $this->success("添加成功！");
                } else {
                    $this->error("添加失败！");
                }

            }
        }


    }